﻿using Clip.DataAccess;
using HZH_Controls.Controls;
using HZH_Controls.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HangzhouChipProject
{
    public partial class productClass  : FrmWithOKCancel1
    {
        string productName;
        double producthight;
        double productwidth;
        double productinterval;
        UCListViewItem uCListViewItem;
        List<ProductClass>  rProductClass;
        public productClass()
        {
            InitializeComponent();
            this.Title = "产品类别";
        }

        List<object> lstSource = new List<object>();
        protected override void OnLoad(EventArgs e)
        {
            DataManipulation.UpdDtaProductclass( out rProductClass);
            for (int i = 0; i < rProductClass.Count; i++)
            {
                lstSource.Add(rProductClass[i].ProductName);
                this.ucListView1.DataSource = lstSource;
            }
        }
        private void ucBtnImg_productadd_BtnClick(object sender, EventArgs e)
        {
            if (GetUIdata())
            {
              //  lstSource.Clear();
                lstSource.Add(productName);
                this.ucListView1.DataSource = lstSource;
                int num = DataManipulation.addProductClassData(productName,producthight,productwidth, productinterval);
                PrintfLog(string.Format("已添加产品 :" +"产品名称: {0}" + "产品方格的宽 * 高 :{1} * {2}", productName, productwidth, producthight));
            }
        }
        private bool GetUIdata()
        {
            try
            {
                productName = this.textBox_ProductName.Text;
                producthight = Double.Parse(this.producthigth_bt.Text);
                productwidth = Double.Parse(this.productwidth_bt.Text);
                productinterval = double.Parse(this.interval_tb.Text);
                return true;
            }
            catch (Exception ex)
            {
                PrintfLog(ex.Message);
                return false;
            }
           
        }

        private void PrintfLog(string slog)
        {
            textBox_infoPintf.AppendText(string.Format("消息提示: {0},{1},{2}", DateTime.Now.ToString(), slog, Environment.NewLine));
        }
        private void ucListView1_SelectedItemEvent(object sender, EventArgs e)
        {
             uCListViewItem = sender as UCListViewItem;     
            string name = uCListViewItem.DataSource.ToString();           
            this.textBox_selectProductName.Text=name;
        }
        private void ucBtnImg_productsub_BtnClick(object sender, EventArgs e)
        {
            if (uCListViewItem==null)
                return;
            object o = uCListViewItem.DataSource;
            lstSource.Remove(o);
            this.ucListView1.DataSource = lstSource;
            DataManipulation.UpdProductclassDta(o.ToString());
        }
        /// <summary>
        /// 设置比较模式！"channel"->输出通道；"doType"->输出通道类型，【0，GPO；1，HSIO】；"cmpMode"->比较模式【0，FIFO模式；1，线性模式；2，等差模式】；"dimension"->比较维度【1，一维；2，二维】；"sourceMode"->比较源【0，FDB；1，CMD】；"sourceX"->比较源X轴号；"sourceY"->比较源Y轴号；"outputMode"->输出模式【0，脉冲；1，电平】；"outputPulseWidth"->输出脉冲宽度
        /// </summary>
        private void Text_bt_Click(object sender, EventArgs e)
        {
          
        }
    }
}
